package com.wnxy.pawnbackgroundsystem.commons;


import com.wnxy.pawnbackgroundsystem.entity.User;
import com.wnxy.pawnbackgroundsystem.exception.DemoRuntimeException;
import com.wnxy.pawnbackgroundsystem.param.UserParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Slf4j
public class ServiceImplUtil {
    public static User getJwtUtilUser(String handName){
        String responseHander = ServletApiUtil.getRequestHander(handName);
        log.info("responseHander:{}",responseHander);
        UserParam userParam = JwtUtils.parseJwt(responseHander);
        if (null == userParam) {
            throw new DemoRuntimeException("执行人未登陆");
        }
        User user = new User();
        BeanUtils.copyProperties(userParam,user);
        return user;
    }
    public static boolean chekePhone(String phone) {
        String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(16[5,6])|(17[0-8])|(18[0-9])|(19[1、5、8、9]))\\d{8}$";
        Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
        Matcher m = p.matcher(phone);
        return m.matches();
    }
}
